<template>
  <div class="result-template pad">
    <div class="head">
      <span>健康测评结果模板设置</span>
    </div>
    <el-table :data="templateList" border stripe v-loading="loading">
      <el-table-column label="年龄">
        <template slot-scope="scope">
          {{scope.row.age}}岁
        </template>
      </el-table-column>
      <el-table-column label="结果话术" prop="contextZ"></el-table-column>
    </el-table>
  </div>
</template>
<script>
import {
  createResultTemplate,
  getResultTemplateList,
  updateResultTemplate,
  deleteResultTemplate
} from '../api/knowledge';
import { formatDate } from '../util';
export default {
  name: 'TestResultTemplate',
  data () {
    return {
      templateList: [],
      loading: false,
      total: 0,
      pageSize: 10,
      searchText: ''
    }
  },
  methods: {
    fetchTemplateList (index) { // 查询结果模板列表
      this.loading = true;
      getResultTemplateList({
        index,
        count: this.pageSize,
        queryParam: {
          contextZ: this.searchText || null // 内容(中文)
        }
      })
      .then(res => {
        if (res.data.code === 1) {
          let list = res.data.data.list || [];
          list.forEach(item => {
            item.createDate = formatDate(item.createDate)
          });
          console.log(list)
          this.templateList = list
          this.total = res.data.data.totalRecord
        } else {
          this.$message.error(res.data.msg || '服务异常!')
        };
        this.loading = false
      })
      .catch(e => {
        this.loading = false;
        this.$message.error('服务异常!')
      })
    }
  },
  created () {
    this.fetchTemplateList(1)
  }
}
</script>
<style lang="scss">
  .result-template {

  }
</style>

